package com.example.pojo.query;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

import static com.example.constant.DateConstant.DEFAULT_DATE_FORMAT;
import static com.example.constant.DateConstant.DEFAULT_DATE_TIME_FORMAT;

@EqualsAndHashCode(callSuper = true)
@Data
public class UserQuery extends PageQuery {
    @ApiModelProperty("用户名")
    private String userName;
    @ApiModelProperty("昵称")
    private String petName;
    @ApiModelProperty("性别")
    private Integer gender;
    //    private Integer age;
    @ApiModelProperty("电话")
    private String phone;
    @ApiModelProperty("邮箱")
    private String email;
    @ApiModelProperty("生日")
    private LocalDate birthday;
    private Integer isDel;
    private Integer isBlack;

    private LocalDateTime createTime;
    private String createStr;
    private String start;
    private LocalDate startTime;
    private String end;
    private LocalDate endTime;
    private LocalDateTime updateTime;

    public void setDate() {
        // 定义一个DateTimeFormatter
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DEFAULT_DATE_TIME_FORMAT);

        // 将LocalDateTime转换为字符串
        if (this.createTime != null) {
            this.createStr = this.createTime.format(formatter).split(" ")[0];
        }

        if (this.startTime != null) {
            formatter = DateTimeFormatter.ofPattern(DEFAULT_DATE_FORMAT);
            this.start = this.startTime.format(formatter);
        }
        if (this.endTime != null) {
            this.end = this.endTime.format(formatter);
        }
    }
}
